package com.wz.project.cxtj.outOrder.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.outOrder.domain.ViewOutOrder;
import com.wz.project.cxtj.outOrder.service.IViewOutOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出库流水Controller
 * 
 * @author wz
 * @date 2022-05-19
 */
@Controller
@RequestMapping("/search/outOrder")
public class ViewOutOrderController extends BaseController
{
    private String prefix = "cxtj/outOrder";

    @Autowired
    private IViewOutOrderService viewOutOrderService;

    @RequiresPermissions("search:outOrder:view")
    @GetMapping()
    public String outOrder()
    {
        return prefix + "/outOrder";
    }

    /**
     * 查询出库流水列表
     */
//    @RequiresPermissions("search:outOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewOutOrder viewOutOrder)
    {
        startPage();
        List<ViewOutOrder> list = viewOutOrderService.selectViewOutOrderList(viewOutOrder);
        return getDataTable(list);
    }

    /**
     * 导出出库流水列表
     */
//    @RequiresPermissions("search:outOrder:export")
    @Log(title = "出库流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewOutOrder viewOutOrder)
    {
        List<ViewOutOrder> list = viewOutOrderService.selectViewOutOrderList(viewOutOrder);
        ExcelUtil<ViewOutOrder> util = new ExcelUtil<ViewOutOrder>(ViewOutOrder.class);
        return util.exportExcel(list, "outOrder");
    }

    /**
     * 新增出库流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库流水
     */
    @RequiresPermissions("search:outOrder:add")
    @Log(title = "出库流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewOutOrder viewOutOrder)
    {
        return toAjax(viewOutOrderService.insertViewOutOrder(viewOutOrder));
    }

    /**
     * 修改出库流水
     */
    @GetMapping("/edit/{jobId}")
    public String edit(@PathVariable("jobId") String jobId, ModelMap mmap)
    {
        ViewOutOrder viewOutOrder = viewOutOrderService.selectViewOutOrderById(jobId);
        mmap.put("viewOutOrder", viewOutOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库流水
     */
    @RequiresPermissions("search:outOrder:edit")
    @Log(title = "出库流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewOutOrder viewOutOrder)
    {
        return toAjax(viewOutOrderService.updateViewOutOrder(viewOutOrder));
    }

    /**
     * 删除出库流水
     */
    @RequiresPermissions("search:outOrder:remove")
    @Log(title = "出库流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewOutOrderService.deleteViewOutOrderByIds(ids));
    }
}
